001 package EVolve.data;
002
003 /* EVolve - an Extensible Software Visualization Framework
004 * Copyright (C) 2001-2002 Qin Wang
005 *
006 * This library is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Library General Public
008 * License as published by the Free Software Foundation; either
009 * version 2 of the License, or (at your option) any later version.
010 *
011 * This library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Library General Public License for more details.
015 *
016 * You should have received a copy of the GNU Library General Public
017 * License along with this library; if not, write to the
018 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
019 * Boston, MA 02111-1307, USA.
020 */
021
022 /*
023 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/
024 */
025
026 import EVolve.data.*;
027
028 public class NumericStringComparator implements EntityComparator {
029 public String getName() {
030 return "Numerical";
031 }
032
033 public int compare(Entity entity1, Entity entity2) {
034 String name1 = entity1.getName();
035 String name2 = entity2.getName();
036
037 try {
038 return Integer.parseInt(name1) - Integer.parseInt(name2);
039 } catch (NumberFormatException e) {
040 return name1.compareTo(name2);
041 }
042 }
043
044 public Object clone() {
045 try {
046 return super.clone();
047 } catch (CloneNotSupportedException e) {
048 return null;
049 }
050 }
051 }